from globals import *


#To implement the 3D effects for the sounds,
#one would have to attach the sound to the object (racer) and have a
#collisionTraverser implemented
#This allows for the audio engine to simulate doppler effects when vehicles passes each other
#
# SADLY we didn't get to implement the actual 3D sounds, but the base functionality is working.
# go to http://www.panda3d.org/manual/index.php/3D_Audio for more info...

#Import wave files
class SoundWAV(object): 
    sound = None 
    def __init__(self, name): 
        self.sound = audio3d.loadSfx('sounds/%s.wav' % name) 

#Import mp3 files
class SoundMP3(object): 
    sound = None 
    def __init__(self, name): 
        self.sound = audio3d.loadSfx('sounds/%s.mp3' % name)


class Sounds():
    def __init__(self):
        
        #--Theme Song Properties and functions--#
        #Initial setup
        self.themeSong = base.loadMusic('sounds/rocky.mp3')
        self.themeSong.setVolume(.25)  
        self.themeSong.setLoopCount(0)
        self.themeSong.setLoop(True)
        
       
       
       
        #---SoundFXs Properties and functions---#
        #Load all sound effects into a list
        #All sound effects in the game are in MONO, since audio3d apparently has problem with
        #stereo files.
        self.sfx = { 
            'acc1': SoundWAV('acc1'), #Acceleration related sounds
            'acc2': SoundWAV('acc2'), 
            'acc3': SoundWAV('acc3'),
            'dec1': SoundWAV('dec1'),
            'dec2': SoundWAV('dec2'), 
            'dec3': SoundWAV('dec3'),
            'max1': SoundWAV('max1'),
            'max2': SoundWAV('max2'),
            'max3': SoundWAV('max3'),
            'engRev1': SoundWAV('engRev1'), #Idle position related sounds
            'engRev2': SoundWAV('engRev2'), 
            'engRev3': SoundWAV('engRev3'),
            'idle': SoundWAV('idle'),
            'carsCrash': SoundWAV('carsCrash'), #Crash related sounds
            'carTerrainCrash': SoundWAV('carTerrainCrash'),
            'tireScreech': SoundWAV('tireScreech'),
            'singleGun': SoundWAV('singleGun'), #Weaapon related sounds
            'rapidGun': SoundWAV('rapidGun'),
            'singleCannon': SoundWAV('singleCannon'), 
            'rapidCannon': SoundWAV('rapidCannon')
        } 
        
    #Play or stop song 
    def playSong(self):    
        self.themeSong.play()
    def stopSong(self):
        self.themeSong.stop()

    #Play sound effect
    def playSound(self, sound_name): 
        the_sound = self.sfx[sound_name].sound 
        the_sound.stop() 
        the_sound.play() 
    
    def stopSound(self, sound_name): 
        the_sound = self.sfx[sound_name].sound 
        the_sound.stop()
    
    #Attach sound effect to node on object - required for 3D effect
    def attachSound(self, sound_name, object_name): 
        the_sound = self.sfx[sound_name].sound 
        audio3d.attachSoundToObject(the_sound, object_name) 

    #Set loop on sound effect on/off
    def loopSound(self, sound_name, bool): 
        the_sound = self.sfx[sound_name].sound 
        the_sound.setLoop(bool)
        
    
    